function initDfInfo(value) {
  const baseAwardDialogUrl = 'https://ustatic.hudongmiao.com/joymewApp/activity/nationalDay/Dialog/awardList/';
  let rank = Number(value.size)
  if (rank > 150) {
    return null
  }
  if (rank > 120) {
    return {
      name: '5斤香米',
      url: `${baseAwardDialogUrl}ENRice.png`,
    }
  }
  if (rank > 80) {
    return {
      name: '嗨喵大礼包',
      url: `${baseAwardDialogUrl}joymewBag.png`,
    }
  }
  if (rank > 50) {
    return {
      name: '倍思充电宝',
      url: `${baseAwardDialogUrl}bsCharger.png`,
    }
  }
  if (rank > 20) {
    return {
      name: '随身wifi',
      url: `${baseAwardDialogUrl}wifi.png`,
    }
  }
  if (rank > 10) {
    return {
      name: '主持司仪宝',
      url: `${baseAwardDialogUrl}xzHost.png`,
    }
  }

  if (rank > 5) {
    return {
      name: '华为GT3手表',
      url: `${baseAwardDialogUrl}HWWatch.png`,
    }
  }
  if (rank > 3) {
    return {
      name: '苹果IPAD AIR',
      url: `${baseAwardDialogUrl}iPadAir.png`,
    }
  }
  if (rank == 3) {
    return {
      name: '苹果IPAD',
      url: `${baseAwardDialogUrl}ipad.png`,
    }
  }
  if (rank == 2) {
    return {
      url: `${baseAwardDialogUrl}iphone14.png`,
      name: '苹果14',
    }
  }
  if (rank == 1) {
    return {
      name: '苹果14PRO',
      url: `${baseAwardDialogUrl}iphone14Pro@v2.png`,
    }
  }
  return null
}

function initJoinList(value) {
  let list = []
  const {
    all_flow,
    // maxInfo
  } = value
  // const max = maxInfo.all_flow
  // const myMoney = Number(all_flow)
  // const topMoney = Number(max)
  if (all_flow > 588) {
    list.push({
      name: '充电宝'
    })
  }
  if (all_flow > 2888) {
    list.push({
      name: '主持司仪宝'
    })
  }
  if (all_flow > 6888) {
    list.push({
      name: '华为GT3手表'
    })
  }
  if (all_flow > 12888) {
    list.push({
      name: '苹果ipad'
    })
  }
  return list
}

function initNextPrize(value) {
  let nextPrize = '获得充电宝抽奖资格'
  const {
    all_flow,
  } = value
  // const max = maxInfo.all_flow
  // const myMoney = Number(all_flow)
  // const topMoney = Number(max)
  if (all_flow > 588) {
    nextPrize = '获得主持司仪宝抽奖资格'
  }
  if (all_flow > 2888) {
    nextPrize = '获得华为GT3手表抽奖资格'
  }
  if (all_flow > 6888) {
    nextPrize = '获得苹果ipad抽奖资格'
  }
  if (all_flow > 12888) {
    nextPrize = '第一名'
  }
  return nextPrize
}

function initNextPrizeMoney(value) {
  let nextMoney = 588
  if(value.type==='second'){
    return '';
  }
  const {
    all_flow,
    maxInfo
  } = value
  const max = maxInfo.all_flow
  // const myMoney = Number(all_flow)
  // const topMoney = Number(max)

  if (all_flow > 588) {
    nextMoney = 2888
  }
  if (all_flow > 2888) {
    nextMoney = 6888
  }
  if (all_flow > 6888) {
    nextMoney = 12888
  }
  if (all_flow > 12888) {
    nextMoney = max
  }
  return nextMoney - all_flow
}
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    value: Object
  },
  observers: {
    'value': function (value) {
      let params = {
        dFInfo: null,
        canJoinList: [],
        nextPrize: '',
        nextPrizeMoney: '',
      }
      params.dFInfo = initDfInfo(value)
      params.canJoinList = initJoinList(value)
      params.nextPrize = initNextPrize(value)
      params.nextPrizeMoney = initNextPrizeMoney(value)

      this.setData(params)
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    dFInfo: null,
    canJoinList: [],
    nextPrize: '',
    nextPrizeMoney: '',
  },
  lifetimes: {
    attached(){
      const { value } = this.data
      let params = {
        dFInfo: null,
        canJoinList: [],
        nextPrize: '',
        nextPrizeMoney: '',
      }
      params.dFInfo = initDfInfo(value)
      params.canJoinList = initJoinList(value)
      params.nextPrize = initNextPrize(value)
      params.nextPrizeMoney = initNextPrizeMoney(value)

      this.setData(params)
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    toRule() {
      this.triggerEvent('update', {
        ruleDialogVisible: true,
      })
    }
  }
})